//
//  HJTabBarViewController.swift
//  HJWeiBo
//
//  Created by 夏航军 on 16/9/22.
//  Copyright © 2016年 夏航军. All rights reserved.
//

import UIKit

class HJTabBarViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        //将 UITabBarController 的属性 tabbar 替换成自定义的tabbar
        //因为tabbar为只读属性,所以要使用KVC进行复制
        let mainTabBar = HJMainTabBar()
        self.setValue(mainTabBar, forKey: "tabBar")
        
        mainTabBar.composeClosure = { [weak self] in
            
            let composeView = HJComposeView()
            composeView.show(target: self!)
            
            //获取window
//            let window = UIApplication.shared.keyWindow
//            window?.addSubview(composeView)
            
        }
    
        
     //添加子控制器
    addChildViewControllers()

    }
    
    private func addChildViewControllers () {
        
        addChildViewController(vc: HJHomeController(), imageName: "tabbar_home", title: "首页")
        
        addChildViewController(vc: HJMessageController(), imageName: "tabbar_message_center", title: "信息")
        addChildViewController(vc: HJDiscoverController(), imageName: "tabbar_discover", title: "发现")
        addChildViewController(vc: HJProfileController(), imageName: "tabbar_profile", title: "我")
        
           }
    
    
   private func addChildViewController (vc : UIViewController , imageName : String , title : String) {
        //设置标题
        vc.title = title;
        //设置默认图片
        vc.tabBarItem.image = UIImage(named: imageName)
        //设置选中图片
        vc.tabBarItem.selectedImage = UIImage(named:imageName + "_selected")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        //设置选中字体颜色
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orange], for: .selected)
        //设置字体颜色
        vc.tabBarItem.setTitleTextAttributes([NSFontAttributeName:UIFont.systemFont(ofSize: 11)], for: .normal)
        
        //修改徽标的颜色
        vc.tabBarItem.badgeColor = UIColor.purple
        //不显示
        vc.tabBarItem.badgeValue = nil
        
        //添加根控制器
         let nav = HJBaseNavController(rootViewController: vc)
        //把根控制器添加到UITabBarController
        addChildViewController(nav)
    }
        
  
    
    
    

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

  

}
